/*
 * Copyright 2006-2023 ahtelit.com, All Rights Reserved.
 */

package com.telit.firecommand.controller;

import com.telit.common.constant.Constant;
import com.telit.common.entity.DataReturn;
import com.telit.common.entity.PageData;
import com.telit.firecommand.dto.DistrictCountDTO;
import com.telit.firecommand.dto.SysEquipStationDTO;
import com.telit.firecommand.service.EquipStationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 气象设备API
 *
 * @author yuezhuang
 * @since 2023-03-31
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/equip-station", produces = MediaType.APPLICATION_JSON_VALUE)
@Api(tags = "气象设备API", value = "气象设备API", produces = MediaType.APPLICATION_JSON_VALUE)
public class EquipStationController {

    private final EquipStationService equipStationService;

    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "name", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", value = "监测站类型（1:气象站，2:水文站）", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "status", value = "状态：1-在线 0-离线", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "districtCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String"),
    })
    @GetMapping(value = "/count", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "查询数量", httpMethod = Constant.REQUEST_METHOD_GET)
    public DataReturn<DistrictCountDTO> count(@RequestParam(required = false) String name,
                                              @RequestParam(required = false) Integer type,
                                              @RequestParam(required = false) Integer status,
                                              @RequestParam(value = "districtCode") String districtCode) {
        return DataReturn.ok(equipStationService.count(districtCode, type, status, name));
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "name", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", value = "监测站类型（1:气象站，2:水文站）", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "status", value = "状态：1-在线 0-离线", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "districtCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String"),
    })
    @GetMapping(value = "/tree-district", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "查询树形结构", httpMethod = Constant.REQUEST_METHOD_GET)
    public DataReturn<DistrictCountDTO> treeDistrict(@RequestParam(required = false) String name,
                                                     @RequestParam(required = false) Integer type,
                                                     @RequestParam(required = false) Integer status,
                                                     @RequestParam(value = "districtCode") String districtCode) {
        return DataReturn.ok(equipStationService.treeDistrict(districtCode, type, status, name));
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "name", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", value = "监测站类型（1:气象站，2:水文站）", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "status", value = "状态：1-在线 0-离线", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "districtCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "current", value = "当前页数", required = true, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "size", value = "每页条数", required = true, paramType = "query", dataType = "int"),
    })
    @GetMapping(value = "/qry-list", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "查询列表", httpMethod = Constant.REQUEST_METHOD_GET)
    public DataReturn<PageData<List<SysEquipStationDTO>>> qryList(@RequestParam(required = false) String name,
                                                                  @RequestParam(required = false) Integer type,
                                                                  @RequestParam(required = false) Integer status,
                                                                  @RequestParam(value = "districtCode") String districtCode,
                                                                  @RequestParam(value = "current", defaultValue = "1") Integer current,
                                                                  @RequestParam(value = "size", defaultValue = "20") Integer size) {
        return DataReturn.ok(equipStationService.qryList(districtCode, type, status, name, current, size));
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query", dataType = "String"),
    })
    @GetMapping(value = "/info/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "详情", httpMethod = Constant.REQUEST_METHOD_GET)
    public DataReturn<SysEquipStationDTO> info(@PathVariable(value = "id") Long id) {
        return DataReturn.ok(equipStationService.info(id));
    }

    @GetMapping(value = "/dealData", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "更新数据", httpMethod = Constant.REQUEST_METHOD_GET)
    public DataReturn<?> dealData() {
        equipStationService.dealData();
        return DataReturn.ok();
    }

}
